home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / Buch / Zins1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-09  |  3.1 KB  |  102 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "Zins1.h"
  6. //---------------------------------------------------------------------------
  7. #pragma resource "*.dfm"
  8.  
  9. TForm1 *Form1;
  10.  
  11. //---------------------------------------------------------------------------
  12. __fastcall TZins::TZins (void) : TObject ()
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16. void __fastcall TZins::SetKapital (String Text)
  17. {
  18.   Kapital = StrToFloat (Text);
  19. }
  20. //---------------------------------------------------------------------------
  21. void __fastcall TZins::SetProzent (String Text)
  22. {
  23.   Prozent = StrToFloat (Text);
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TZins::SetZinsen (String Text)
  27. {
  28.   Zinsen = StrToFloat (Text);
  29. }
  30. //---------------------------------------------------------------------------
  31. String __fastcall TZins::CalcKapital (void)
  32. {
  33.   Kapital = Zinsen * 100 / Prozent;
  34.   return (String(FloatToStrF(Kapital,ffNumber,8,2)));
  35. }
  36. //---------------------------------------------------------------------------
  37. String __fastcall TZins::CalcProzent (void)
  38. {
  39.   Prozent = Zinsen * 100 / Kapital;
  40.   return (String(FloatToStrF(Prozent,ffNumber,8,2)));
  41. }
  42. //---------------------------------------------------------------------------
  43. String __fastcall TZins::CalcZinsen (void)
  44. {
  45.   Zinsen = Kapital * Prozent / 100;
  46.   return (String(FloatToStrF(Zinsen,ffNumber,8,2)));
  47. }
  48. //---------------------------------------------------------------------------
  49. __fastcall TForm1::TForm1(TComponent* Owner)
  50.     : TForm(Owner)
  51. {
  52. }
  53. //---------------------------------------------------------------------------
  54. void __fastcall TForm1::SetZero (void)
  55. {
  56.   Zins1->Kapital = 0;
  57.   Zins1->Prozent = 0;
  58.   Zins1->Zinsen  = 0;
  59.   Edit1->Text = "0";
  60.   Edit2->Text = "0";
  61.   Edit3->Text = "0";
  62.   Modus = 0;
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TForm1::FormCreate(TObject *Sender)
  66. {
  67.   Zins1 = new TZins ();
  68.   SetZero ();
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TForm1::Button1Click(TObject *Sender)
  72. {
  73.   SetZero ();
  74.   Label1->Caption = "Gib fⁿr die gesuchte Gr÷▀e eine Null ein!";
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TForm1::Button2Click(TObject *Sender)
  78. {
  79.   Zins1->SetKapital (Edit1->Text);
  80.   if (Edit1->Text == "0") Modus++;
  81.   Zins1->SetProzent (Edit2->Text);
  82.   if (Edit2->Text == "0") Modus+=10;
  83.   Zins1->SetZinsen  (Edit3->Text);
  84.   if (Edit3->Text == "0") Modus+=100;
  85.   switch (Modus)
  86.   {
  87.     case 1:
  88.       Edit1->Text = Zins1->CalcKapital();
  89.       break;
  90.     case 10:
  91.       Edit2->Text = Zins1->CalcProzent ();
  92.       break;
  93.     case 100:
  94.       Edit3->Text = Zins1->CalcZinsen ();
  95.       break;
  96.     default:
  97.       Label1->Caption = "Das sind zu viele Nullen!";
  98.   }
  99.   Modus = 0;
  100. }
  101. //---------------------------------------------------------------------------
  102.